package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.MeetingRoomMonitorPageQueryDTO;
import com.sky.dto.MonitorDTO;
import com.sky.entity.MeetingRoom;
import com.sky.entity.Monitor;
import com.sky.mapper.MonitorMapper;
import com.sky.result.PageResult;
import com.sky.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class MonitorServiceImpl implements MonitorService {

    @Autowired
    private MonitorMapper monitorMapper;

    @Override
    // 分页查询会议室监控信息
    public PageResult pageQuery(MeetingRoomMonitorPageQueryDTO meetingRoomMonitorPageQueryDTO) {
        // 设置分页参数
        PageHelper.startPage(meetingRoomMonitorPageQueryDTO.getPage(),meetingRoomMonitorPageQueryDTO.getPageSize());   //设置分页查询参数

        // 调用mapper查询数据
        Page<MeetingRoom> page = monitorMapper.pageQuery(meetingRoomMonitorPageQueryDTO);

        Long total=page.getTotal(); // 满足条件的总记录数
        List<MeetingRoom> meetingRoomList=page.getResult(); //满足条件的所有记录

        return new PageResult(total,meetingRoomList);
    }


    @Override
    // 调用会议室监控服务
    public boolean callMeetingRoomMonitor(Long id, MonitorDTO monitorDTO) {
        Monitor monitor = new Monitor();
        monitor.setMeetingRoomId(id);
        monitor.setStatus(monitorDTO.getStatus());
        monitor.setNotes(monitorDTO.getNotes());
        monitor.setMonitorTime(LocalDateTime.now());

        // 调用mapper插入数据
        monitorMapper.insert(monitor);

        return true;

    }

    @Override
    public List<Monitor> getMonitorDetailById(Long id) {
        // 调用mapper查询数据
        return monitorMapper.getMonitorById(id);
    }

}
